home *** CD-ROM | disk | FTP | other *** search
/ Technotools / Technotools (Chestnut CD-ROM)(1993).ISO / lang_c / bldfuncs / getf.m < prev   
Text File  |  1989-04-26  |  5KB  |  178 lines

  1.  
  2. ;**Last revision : Wednesday April 26, 1989 at 9:23 pm
  3.  
  4. ;**   getf - Copyright 1988 by Marvin Hymowech.
  5. ;**        - Prompts for a function name, extracts the name of the file
  6. ;**        - in which it is defined from "funcs.txt" and presents the file
  7. ;**        - in the current window.
  8. ;**        - Returns: 0 if error, else 1.
  9.  
  10.  
  11. #define NON_SYSTEM 0
  12.  
  13. ( macro getf
  14.    (
  15.       (int start_buf_id func_buf_id)
  16.       (string fn_name line file_name)
  17.  
  18.          ;** make fn_name a global so that it will retain its prior
  19.          ;** value for the default display in the get_parm below
  20.       (global fn_name)
  21.  
  22.  
  23.          ;** get desired function name from user
  24.       (if
  25.          ((!
  26.             (get_parm NULL fn_name "Enter function name: " NULL fn_name))
  27.          )
  28.          (return 0)
  29.       )
  30.  
  31.          ;** verify that funcs.txt exists on disk in the current directory
  32.       (if (!(exist "funcs.txt"))
  33.          (
  34.             (beep)
  35.             (error "file funcs.txt not found")
  36.             (return 0)
  37.          )
  38.       )
  39.  
  40.          ;** save current buff_id, so we can restore it if an error occurs
  41.       ( = start_buf_id (inq_buffer))
  42.          
  43.          ;**create a buffer for funcs.txt without attaching it to a window
  44.       (if
  45.          (!( = func_buf_id
  46.             (create_buffer "functions" "funcs.txt" NON_SYSTEM)
  47.           )
  48.          )
  49.          (
  50.             (beep)
  51.             (error "Can't load funcs.txt file.")
  52.             (return 0)
  53.          )
  54.       )
  55.  
  56.          ;** make it the current buffer
  57.       (set_buffer func_buf_id)
  58.  
  59.          ;** Brief back-end buffer functions won't set tabs for us
  60.          ;** like edit_file, so we do it explictly
  61.       (tabs 9 17)
  62.  
  63.       (top_of_buffer)
  64.  
  65.          ;** search for the function name
  66.       (while 1
  67.          (
  68.             ;** break if function anme not found
  69.             (if ( <= (search_fwd fn_name)0)
  70.                (
  71.                   (beep)
  72.                   (error "function %s not found" fn_name)
  73.                      ;** restore the original buffer
  74.                   (set_buffer start_buf_id)
  75.                   (return 0)
  76.                )
  77.             )
  78.                ;** get the current line into variable "line"
  79.             (beginning_of_line)
  80.             (sprintf line "%s" (read) )
  81.  
  82.                ;** if fn line, not file line
  83.             (if (==(index line "\t")1)
  84.                (
  85.  
  86.                   ;** read the line into "line" starting after the tab
  87.                (next_char)
  88.                (sprintf line "%s" (read) )
  89.  
  90.                   ;** make sure we have the exact function name, not
  91.                   ;** part of a larger function name.
  92.  
  93.                   ;** if the line consists of \t,fn_name, and \n,
  94.                   ;** then break
  95.                (if (==(index line "\n") ( + 1 (strlen fn_name)))
  96.                   (break)
  97.                )
  98.  
  99.                   ;** if the line consists of \t,fn_name, ;, and \n
  100.                   ;** then break
  101.                (if(==(index line ";") ( + 1 (strlen fn_name)))
  102.                   (break)
  103.                )
  104.             )
  105.          )
  106.          (end_of_line)     ;** else try next line
  107.       )
  108.    )
  109.    (if (<= (search_back ":")0)  ;** done, get the file name
  110.       (
  111.          (beep)
  112.          (error "fincs.txt corrupted")
  113.          (set_buffer start_buf_id)
  114.          (return 0)
  115.       )
  116.    )
  117.  
  118.    (beginning_of_line)
  119.    (sprintf line "%s" (read))
  120.    (sprintf file_name "%s"       ;** get rid of trailing ":"
  121.       (substr line 1 (-(index line ":")1)))
  122.  
  123.  
  124.       ;** verify that the file exists on disk
  125.    (if(!(exist file_name))
  126.       (
  127.          (beep)
  128.          (error "file %s not found" file_name)
  129.          (set_buffer start_buf_id)
  130.          (return 0)
  131.       )
  132.    )
  133.  
  134.       ;** and edit it
  135.    (edit_file file_name)
  136.       ;** try to place cursor on the function definition
  137.    (return(funcsrch fn_name))
  138.    )
  139. )
  140.  
  141. ;** funcsrch - Copyright 1988 Marvin Hymowech
  142. ;**          - Searches the current buffer for a string (function name)
  143. ;**          - by starting from the end of the buffer.
  144. ;**          - This is designed to position the cursor on
  145. ;**          - a function definition since most functions tend to be
  146. ;**          - used before thet are defined.
  147. ;**          - Returns: 0 if function not found, 1 if found
  148. (macro funcsrch
  149.    (
  150.       (string s)
  151.       (extern _s_pat _dir center_line)
  152.  
  153.       (get_parm 0 s)
  154.       (message "locating function %s..." s)
  155.       (end_of_buffer)
  156.       (if(> (search_back s)0)
  157.          (
  158.             (message "function %s found" s)
  159.             (center_line)
  160.             (sprintf _s_pat "%s" s)
  161.             (= _dir 0)
  162.             (return 1)
  163.          )
  164.       ;else
  165.          (
  166.             (top_of_buffer)
  167.             (beep)
  168.             (error "function %s not found" s)
  169.             (return 0)
  170.          )
  171.       )
  172.    )
  173. )
  174.  
  175.  
  176.  
  177.  
  178.